package com.tr.syn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TRasdzz
 * @since  2021/3/11 12:35
 * @version  1.0
 */
//线程不安全的集合
public class UnSafeList {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        for (int i = 0; i < 10000; i++) {

            new Thread(() -> {
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();

        }
        System.out.println(list.get(9995));
        System.out.println(list.size());
    }
}
//10000